package com.calm.cdemo.activitytransition;

import android.app.ActivityOptions;
import android.content.Intent;
import android.os.Build;
import android.support.v7.widget.DividerItemDecoration;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.widget.TextView;

import com.calm.cdemo.R;
import com.calm.cdemo.base.BaseActivity;
import com.calm.cdemo.bean.MenuBean;
import com.calm.clibrary.rvadapter.CommRvAdapter;
import com.calm.clibrary.rvadapter.CommRvHolder;
import com.calm.clibrary.utils.Constant;

import java.util.ArrayList;
import java.util.List;

/**
 * Create by Calm
 * 2020/1/9 11:03
 * 转场动画菜单
 */
public class TransitionActivityMenu extends BaseActivity {
    @Override
    protected int getLayoutId() {
        return R.layout.transitionactivitymenu;
    }

    @Override
    protected void init() {
        RecyclerView rvList = findViewById(R.id.transitionactivitymenu_rv_list);
        rvList.setLayoutManager(new LinearLayoutManager(mActivity));
        rvList.addItemDecoration(new DividerItemDecoration(mActivity, LinearLayoutManager.VERTICAL));
        CommRvAdapter<MenuBean> adapter = new CommRvAdapter<MenuBean>(mActivity,getMenuList(),R.layout.main_item) {
            @Override
            public void bindData(CommRvHolder holder, final MenuBean data, int position) {
                final TextView tvName = holder.getViw(R.id.main_item_tv_name);
                tvName.setText(data.name);
                holder.setCommRvOnItemClickListener(new CommRvHolder.CommRvOnItemClickListener() {
                    @Override
                    public void onItemClickListener(int position) {
                        String s;
                        if(position == 9){
                            s = data.name;
                        }else {
                            s = data.name+"\n"+data.description;
                        }
                        Intent intent = new Intent(mActivity,data.toClass);
                        intent.putExtra(Constant.Params0,s);
                        intent.putExtra(Constant.Params1,position);
                        if(position < 6){
                            startActivity(intent);
                        }
                        if(position >= 6 && position <= 8){
                            if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP){
                                startActivity(intent, ActivityOptions.makeSceneTransitionAnimation(mActivity).toBundle());
                            }
                        }
                        if(position == 9){
                            if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP){
                                startActivity(intent, ActivityOptions.makeSceneTransitionAnimation(mActivity,tvName,"shareTxt").toBundle());
                            }
                        }
                        switch (position){
                            case 0:
                                overridePendingTransition(R.anim.fade_in,R.anim.fade_out);
                                break;
                            case 1:
                                overridePendingTransition(R.anim.slide_in_left,R.anim.slide_out_right);
                                break;
                            case 2:
                                overridePendingTransition(R.anim.slide_in_right,R.anim.slide_out_left);
                                break;
                            case 3:
                                overridePendingTransition(R.anim.zoom_in,R.anim.zoom_out);
                                break;
                            case 4:
                                overridePendingTransition(R.anim.slide_in_top,R.anim.slide_out_bottom);
                                break;
                            case 5:
                                overridePendingTransition(R.anim.slide_in_bottom,R.anim.slide_out_top);
                                break;
                        }
                    }
                });
            }
        };
        rvList.setAdapter(adapter);
    }
    private List<MenuBean> getMenuList(){
        List<MenuBean> menus = new ArrayList<>();
        MenuBean b0 = new MenuBean();
        b0.name = "淡入淡出";
        b0.toClass = TranisitionActivity.class;
        b0.description = "淡入淡出效果";
        menus.add(b0);
        MenuBean b1 = new MenuBean();
        b1.name = "左进右出";
        b1.toClass = TranisitionActivity.class;
        b1.description = "左进右出效果";
        menus.add(b1);
        MenuBean b2 = new MenuBean();
        b2.name = "右进左出";
        b2.toClass = TranisitionActivity.class;
        b2.description = "右进左出效果";
        menus.add(b2);
        MenuBean b3 = new MenuBean();
        b3.name = "中心缩放";
        b3.toClass = TranisitionActivity.class;
        b3.description = "中心缩放效果";
        menus.add(b3);
        MenuBean b4 = new MenuBean();
        b4.name = "上进下出";
        b4.toClass = TranisitionActivity.class;
        b4.description = "上进下出效果";
        menus.add(b4);
        MenuBean b5 = new MenuBean();
        b5.name = "下进上出";
        b5.toClass = TranisitionActivity.class;
        b5.description = "下进上出效果";
        menus.add(b5);
        MenuBean b6 = new MenuBean();
        b6.name = "分解(适用于5.0以上版本)";
        b6.toClass = TranisitionActivity.class;
        b6.description = "分解效果";
        menus.add(b6);
        MenuBean b7 = new MenuBean();
        b7.name = "滑动(适用于5.0以上版本)";
        b7.toClass = TranisitionActivity.class;
        b7.description = "滑动效果";
        menus.add(b7);
        MenuBean b8 = new MenuBean();
        b8.name = "淡出(适用于5.0以上版本)";
        b8.toClass = TranisitionActivity.class;
        b8.description = "淡出效果";
        menus.add(b8);
        MenuBean b9 = new MenuBean();
        b9.name = "元素共享(适用于5.0以上版本)";
        b9.toClass = TranisitionActivity.class;
        b9.description = "元素共享效果";
        menus.add(b9);
        return menus;
    }
}
